/*******************************************************************************
 * copyright (c) 2009 - 2010 Simon Allen
 *
 * This file is part of Convex Media Converter.
 *
 * Convex Media Converter is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Convex Media Converter is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with Convex Media Converter; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 ******************************************************************************/


#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H

#include "ConvertDialog/convertdialog.h"
#include "AboutDialog/aboutdialog.h"
#include "Preferences/preferences.h"
#include "OutputSettings/outputsettings.h"
#include "FileProperties/fileproperties.h"
#include "ui_mainwindow.h"

#include <QtGui>

using namespace std;


class MainWindow: public QMainWindow
{
	Q_OBJECT

	private:
		const static QString PRESET_FILE;
		Ui::MainWindow *ui;
		AboutDialog *aboutDialog;
		Preferences *preferences;
		ConvertDialog *convertDialog;
		OutputSettings outputSettings;
		PresetSettings *userSettings;
		QList<QFileInfo> inputFiles;
		QFileInfo currentInputFile;
		QStringList codecsFound;
		QLabel statusLabel;

	signals:
		void resized(QResizeEvent event);

	protected:
		void resizeEvent(QResizeEvent *event);
		void dragEnterEvent(QDragEnterEvent *event);
		void dropEvent(QDropEvent *event);
		void closeEvent(QCloseEvent *event);

	public:
		MainWindow(QWidget *parent = NULL);
		~MainWindow();

		void setupFormats();
		void setupAudioBitrates();
		void setupAudioModes();
		void setupAudioChannels();
		void setupVideoStandards();
		bool initCodecs();
		int setupEncoders(const QString ffmpegLoc);
		bool codecSupported(const QString codec) const
		{ return codecsFound.contains(codec); }
		int numCodecs() const { return codecsFound.size(); }
		void detectCodecs();
		void setupAudioEncoders();
		void setupVideoEncoders();
		void syncGlobalSettings();
		void setGeometry();
		void setIcons();
		bool checkValidSettings();
		void updateOutputSettings();
		void updateAudioOutputSettings();
		void updateVideoOutputSettings();
		void addInputFiles(const QStringList files);
		void deletePreset(const QString preset);

		public slots:
			void about();
			bool isMediaFile(QString fileName) const;
			void addInputFiles();
			void removeInputFiles();
			void clearInputFiles();
			void resizeInputFiles(QResizeEvent event);
			void showProperties();
			void showInputFileContextMenu(const QPoint &pos);
			void presetChanged(QString newPreset);
			void formatChanged(QString newIndex);
			void audioCodecChanged(const QString newIndex);
			void videoCodecChanged(const QString newCodec);
			void videoStandardChanged(const QString videoStandard);
			void videoAspectChanged(const QString newAspect);
			void addCmdOption();
			void removeCmdOptions();
			void clearCmdOptions();
			void updateCmdOptions();
			void selectOutputDir();
			void newPreset();
			void savePreset();
			void clearPreset();
			void deleteSelectedPreset();
			void revertPreset();
			void showPreferences();
			void convert();
			void cancelConversion();
};

#endif
